# Maintainer: @naveen521kk on Github, Naveen M K <naveen521kk@gmail.com>

_perlname=Win32-API
_realname="${_perlname,,}"
pkgbase=mingw-w64-perl-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-perl-${_realname}")
pkgver=0.84
pkgrel=5
pkgdesc="Perl Win32 API Import Facility (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://metacpan.org/release/Win32-API"
groups=("${MINGW_PACKAGE_PREFIX}-perl-modules")
depends=(
  "${MINGW_PACKAGE_PREFIX}-perl"
  "${MINGW_PACKAGE_PREFIX}-perl-encode-compat"
  "${MINGW_PACKAGE_PREFIX}-perl-math-int64"
)
options=('!emptydirs')
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-cc"
             $([[ ${MINGW_PACKAGE_PREFIX} != *-clang-* ]] || \
                echo "${MINGW_PACKAGE_PREFIX}-gcc-compat"))
license=('perl_5')
source=(
  "https://cpan.metacpan.org/authors/id/B/BU/BULKDD/Win32/${_perlname}-${pkgver}.tar.gz"
  "patchmakefile.py"
  "0001-clang-as-defines.patch"
)
sha512sums=('61ca8bce67fa9d012668f5b658ea2a777d4643c160edfd106fae431181c877be041c0bffa7ce0b89f06e5e817f6dec1cf790ab6ca94d22d767f870c83519c935'
            'd7ec5ba4a3d75f674f4028e8a53bc4177ab71a379bc63affebf910e1d5a0e491b6642318218b55ddc4d90e0125d61e4b97626782af57d44522bcb5543fb21cb2'
            '4d784bfcf8fe4a2c2ce25bdb24fece1ee16994ce4e13d18d19436773d63f2bcfa77360b21d796b5211f7c0a0136e13fe2ce6bd12bcad2802680ce1ecb8739dc5')

prepare() {
  cd "$srcdir/${_perlname}-${pkgver}"
  patch -Np1 -i "${srcdir}/0001-clang-as-defines.patch"
}

build() {
  cd "$srcdir/${_perlname}-${pkgver}"
  PERL_MM_USE_DEFAULT=1 perl Makefile.PL
  export pkgdir=$pkgdir
  python $srcdir/patchmakefile.py
  mingw32-make
}

package() {
  cd "$srcdir/${_perlname}-${pkgver}"
  mingw32-make DESTDIR="${pkgdir}/" install
}
